<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>客户信息管理页</title>
		<link rel="stylesheet" href="../../lib/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../static/css/font.css">
		<link rel="stylesheet" href="../../static/css/weadmin.css">
		<style>
			select{
				width: 150px;
				color: #666;
				height: 38px;
			    line-height: 1.3;
			    border:1px solid #e6e6e6;
			    background-color: #fff;
			    border-radius: 2px;
			    padding-left: 5px;
			}
		</style>
	</head>

	<body>
		<div class="weadmin-nav">
			<span class="layui-breadcrumb" style="visibility: visible;">
		        <a href="">客户管理</a>
		        <a>
	          		<cite>客户信息列表</cite>
		        </a>
	      	</span>
			<a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
				<i class="layui-icon" style="line-height:30px">ဂ</i>
			</a>
		</div>
		<div class="wrap">
			<blockquote class="layui-elem-quote news_search">
				<div class="layui-inline">
					<a id="" class="layui-btn layui-btn-normal" onclick="WeAdminShow('新增标签','./tag-add.html')">添加</a>
					<button id="staff_excel_import_btn_hide" style="display:none" type="button" class="layui-btn"><i class="layui-icon">&#xe67c;</i>批量导入</button>
				    <button id="staff_excel_import_btn_click" onclick="importClick()" type="button" class="layui-btn"><i class="layui-icon">&#xe67c;</i>批量导入</button>
			        <button class="layui-btn" onclick="exportTag()"><i class="layui-icon"></i>批量导出</button>
				</div>
			
				
			</blockquote>
		
			<!-- 数据表格 -->
			<table class="layui-table" lay-filter="kpiItem_table" id="kpiItem_table" style="margin: 0"></table>
		</div>
		<script src="../../publicjs/jquery-1.8.0.min.js"></script>
		<script src="../../lib/layui/layui.js"></script>
		<script src="../../static/js/admin.js" charset="utf-8"></script>
		<script src="../../publicjs/smallkingutil.js"></script>
		
		
		<script>
			layui.use(['upload', 'table'], function() {
				var table = layui.table;
				var form = layui.form;
				window.form = form;
				var upload = layui.upload;
				// layui上传组件
				 var uploadInst = upload.render({
					elem: '#staff_excel_import_btn_hide',
					url: commonUtil.domain() + '/wxwork/admin/tag/importTag',
					accept: 'file',
					field: 'file',
					before: function(res) {
						layer.msg("上传解析中，请稍后。", {
							time: 1000
						});
						layer.load(1, {
							shade: [0.1, '#fff']
						});
					},
					done: function(res) {
						//上传完毕回调
						console.info(res);
						var msg = res.msg;
						if(res.code == 500) {
							if(res.data) {
								var failList = res.data;
								msg += "，请检查Excel中标签名称是否重复信息是否合法。";
							}
						}
						layer.alert(msg, function() {
							kpiItemTable.refresh();
							layer.closeAll();
						});

					},
					error: function() {
						//请求异常回调
						layer.alert("服务器出错，上传失败。");
					}
				}); 
				
				
				// 加载数据表格
				window.kpiItemTable = table.render({
					id: 'kpiItemTable',
					elem: '#kpiItem_table',
					url: commonUtil.domain() +'/wxwork/admin/tag/getTagList', // 数据接口
					method: 'get',
					page: true, // 开启分页
					request: {
						pageName: 'pageNum', // 分页当前页数发给后台的参数名
						limitName: 'pageSize', // 分页每页多少条发给后台的参数名
						categoryId:'1'
					},
					done:function(res){
					   
						$('.layui-laypage-count').text('共'+res.total+'条')
					},
					cols: [
						[ //表头
							 // 如果那天说这个表格要导出了 放开代码
							 // {type: 'checkbox', fixed: 'left'},
						  {
								field: 'tagName',
								title: '标签名称',
								width: 200
							},{
								field: 'oper',
								title: '操作',
								width: 100,
								templet: '#oper'
							}
							
						]
					]
				});
				// 导出按钮
				window.exportTag = function(res) {
					location.href = commonUtil.domain() + "/wxwork/admin/tag/exportTag";
				}
				
				// 上传提示
				window.importClick = function(res) {
					$("#staff_excel_import_btn_hide").click()
					/* layer.confirm('导入提示：如果导入Excel中的员工号已存在于系统，则不会覆盖原有数据。', function(index) {
						$("#staff_excel_import_btn_hide").click()
					}); */
				}
				// 刷新表格
				kpiItemTable.refresh = function(data) {
					kpiItemTable.reload({
						where: data,
						page: {
							curr: 1 //重新从第 1 页开始
						}
					});
				}
				// TODO 导出按钮
				window.kpiItemSearch = function(res){
					var checkStatus = table.checkStatus("kpiItemTable");
				    var data = checkStatus.data; // 获取选中的数据
				    table.exportFile("kpiItemTable", data, 'excel');
				}
				// 下拉框变更事件
				window.kpiTypeChange = function(res){
					var type = $('#kpi_type option:selected').val();
					var data = {};
					if(type != -1){
						data.type = type;	
					}
					kpiItemTable.refresh(data);
				}
				
				
				// 监听表单提交
				table.on('tool(kpiItem_table)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
					  var data = obj.data; // 获得当前行数据
					  var layEvent = obj.event; // 获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
					  var tr = obj.tr; // 获得当前行 tr 的DOM对象
					  if(layEvent == 'delete'){ // 点击表格一行的移除按钮
							 layer.confirm("确定要删除此标签名称吗？", function(index){
								// 发送ajax请求 删除地区
								var ajaxParam = {
									url : commonUtil.domain() + "/wxwork/admin/tag/deleteTag",//删除接口地址
									data : {
										id : data.id
									}
								}
								ajaxUtil.post(ajaxParam, function(){
									layer.closeAll();
									kpiItemTable.refresh();
								});
							 });
					  }else if(layEvent == 'update'){
						  WeAdminShow('修改标签','tag-add.html?id=' + data.id)
					  }
				});
			});
		</script>
	
		<script type="text/html" id="oper">
  			<a title="修改" lay-event="update"><i class="layui-icon">&#xe642;</i></a>
		    <a title="删除" lay-event="delete"><i class="layui-icon">&#xe640;</i></a>
		</script>
	</body>

</html>